package com.tuyou.cloud.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloRibbonService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "helloFallback")
    public String hello() {
        return restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody();
    }

    public String helloFallback() {
        return "hello error";
    }

    @HystrixCommand(fallbackMethod = "paramFallback")
    public String param(String name, Integer age) {
        return restTemplate.getForObject("http://HELLO-SERVICE/param", String.class, name ,age);
    }

    public String paramFallback(String name, Integer age) {
        return "param error";
    }
}
